package cn.tedu.weibo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class LogAspect {
    @Before("execution(public cn.tedu.weibo.result.JsonResult cn.tedu.weibo.controller.*.*(..))")
    public void before(JoinPoint point){
        String simpleName = point.getTarget().getClass().getSimpleName();
        String name = point.getSignature().getName();
        log.info(simpleName+"."+name+"()开始执行");
    }
    @AfterReturning("execution(public cn.tedu.weibo.result.JsonResult cn.tedu.weibo.controller.*.*(..))")
    public void afterReturning(JoinPoint point){
        String simpleName = point.getTarget().getClass().getSimpleName();
        String name = point.getSignature().getName();
        log.info(simpleName+"."+name+"()执行完毕");
    }
    @AfterThrowing(
            value = "execution(public cn.tedu.weibo.result.JsonResult cn.tedu.weibo.controller.*.*(..))",
            throwing = "e"
    )
    public void afterThrowing(JoinPoint point,Exception e){
//        String simpleName = point.getTarget().getClass().getSimpleName();
//        String name = point.getSignature().getName();
//        log.error(simpleName+"."+name+"()抛出异常，异常是:"+e.getMessage(),e);
        log.error(e.getMessage(),e);
    }
}
